package models

import "time"

import "fmt"
import "haili/common"
import "strconv"

type UserModel struct{}
type User struct {
	ID       string    `xorm:" varchar(34)  notnull unique 'ID' "` //主键
	Phone    string    `xorm:" pk unique 'Phone'"`                 //手机号
	PassWord string    `xorm:"'PassWord'"`                         //密码
	NickName string    `xorm:"'NickName'"`                         //昵称
	Name     string    `xorm:"'Name'"`                             //姓名
	IDCard   string    `xorm:"'IDCard'"`                           //身份证
	BankCard string    `xorm:"'BankCard'"`                         //银行卡
	Country  string    `xorm:"'Country'"`                          //国家
	Address  string    `xorm:"'Address'"`                          //地址
	Avatar   string    `xorm:"'Avatar'"`                           //头像
	Type     string    `xorm:"'Type'"`                             //类型
	Status   string    `xorm:"'Status'"`                           //状态
	ReMark   string    `xorm:"'ReMark'"`                           //备注
	CreateAt time.Time `xorm:"created 'CreatedAt'"`                //创建日期
	UpdateAt time.Time `xorm:"created 'UpdatedAt'"`                //更新日期
}

func (UserModel) Find(params map[string]interface{}) []User {
	var users []User
	fmt.Println(params)
	//common.DB.Where(params).Find(&users)
	return users
}

func (UserModel) Select(user *User) (bool, error) {
	s, e := common.DB.Table("users").Get(user)
	fmt.Println("userModel--------", user)
	return s, e
}

func (UserModel) Insert(user *User) error {
	user.ID = strconv.Itoa(time.Now().Nanosecond())
	fmt.Println(strconv.Itoa(time.Now().Nanosecond()))
	_, e := common.DB.Table("users").Insert(user)
	return e
}

func (UserModel) Update(user User) (int64, error) {
	affected, err := common.DB.Table("users").Id(user.Phone).Update(user)
	if nil != err {
		return 0, err
	}
	return affected, nil
}
